<?php
namespace api\modules\v1\controllers;

use api\components\ApiController;
use api\modules\v1\models\Address;
use api\modules\v1\models\Coin;
use api\modules\v1\models\Wallet;
use Yii;
use yii\base\Object;

/**
 * 信息控制器
 * @author CGA
 */
class AccountController extends ApiController
{
    /**
     * 支付方式简易列表
     * @author wj
     */
    public function actionPayList()
    {
        $model = new Wallet();
        if ($result = $model->listPay()) {
            return ['message' => '支付方式获取成功', 'data' => $result];
        } else {
            return ['message' => '支付方式获取成功', 'data' => []];
        }
    }

    /**
     * 可用币查询
     * @author zcy
     */
    public function actionCoinAmount()
    {
        $params = Yii::$app->request->post();
        $model = new Coin();
        $model->setScenario(Coin::SCENARIO_GET_AMOUNT);
        $model->load($params, '');
        if ($result = $model->getCoinAmount()) {
            return ['message' => '可用币种数量获取成功', 'data' => $result];
        }

    }

    /**
     * 支付方式列表
     * @author wj
     */
    public function actionWalletList()
    {
        $params = Yii::$app->request->post();
        $model = new Wallet();
        $model->setScenario(Wallet::SCENARIO_WALLET_LIST);
        $model->load($params, '');
        if ($result = $model->listWallet()) {
            return ['message' => '收款信息列表获取成功', 'data' => $result];
        }
    }

    /**
     * 支付方式绑定
     * @author wj
     */
    public function actionWalletBind()
    {
        $params = Yii::$app->request->post();
        $model = new Wallet();
        $model->setScenario(Wallet::SCENARIO_WALLET_BIND);
        $model->load($params, '');
        if ($result = $model->bindWallet()) {
            return ['message' => '收款信息绑定成功', 'data' => $result];
        }
    }

    /**
     * 支付方式修改
     * @author wj
     */
    public function actionWalletUpdate()
    {
        $params = Yii::$app->request->post();
        $model = new Wallet();
        $model->setScenario(Wallet::SCENARIO_WALLET_UPDATE);
        $model->load($params, '');
        if ($result = $model->updateWallet()) {
            return ['message' => '支付方式修改成功', 'data' => $result];
        }
    }

    /**
     * 支付方式删除
     * @author wj
     */
    public function actionWalletDelete()
    {
        $params = Yii::$app->request->post();
        $model = new Wallet();
        $model->setScenario(Wallet::SCENARIO_WALLET_DELETE);
        $model->load($params, '');
        if ($result = $model->deleteWallet()) {
            return ['message' => '支付方式删除成功', 'data' => $result];
        }
    }

    /**
     * 设置默认支付方式
     * @author wj
     */
    public function actionWalletDefault()
    {
        $params = Yii::$app->request->post();
        $model = new Wallet();
        $model->setScenario(Wallet::SCENARIO_WALLET_DEFAULT);
        $model->load($params, '');
        if ($result = $model->setDefault()) {
            return ['message' => '设置默认支付方式成功', 'data' => $result];
        }
    }

    /**
     * 提币地址列表
     * @author wj
     */
    public function actionOutaddrList()
    {
        $params = Yii::$app->request->post();
        $model = new Address();
        $model->setScenario(Address::SCENARIO_OUT_LIST);
        $model->load($params, '');
        if ($result = $model->listOutAddr()) {
            return ['message' => '提币信息列表获取成功', 'data' => $result];
        }
    }

    /**
     * 提币地址绑定
     * @author WJ
     */
    public function actionOutaddrBind()
    {
        $params = Yii::$app->request->post();
        $model = new Address();
        $model->setScenario(Address::SCENARIO_OUT_BIND);
        $model->load($params, '');
        if ($result = $model->bindOutAddr()) {
            return ['message' => '提币地址绑定成功', 'data' => $result];
        }
    }

    /**
     * 提币地址修改
     * @author WJ
     */
    // public function actionOutaddrUpdate()
    // {
    //     $params = Yii::$app->request->post();
    //     $model = new Address();
    //     $model->setScenario(Address::SCENARIO_OUT_UPDATE);
    //     $model->load($params, '');
    //     if ($result = $model->updateOutAddr()) {
    //         return ['message' => '提币地址修改成功', 'data' => $result];
    //     }
    // }

    /**
     * 提币地址删除
     * @author WJ
     */
    public function actionOutaddrDelete()
    {
        $params = Yii::$app->request->post();
        $model = new Address();
        $model->setScenario(Address::SCENARIO_OUT_DELETE);
        $model->load($params, '');
        if ($result = $model->deleteOutAddr()) {
            return ['message' => '提币地址删除成功', 'data' => $result];
        }
    }

    /**
     * 设置为默认提币地址
     * @author WJ
     */
    public function actionOutaddrDefault()
    {
        $params = Yii::$app->request->post();
        $model = new Address();
        $model->setScenario(Address::SCENARIO_OUT_DEFAULT);
        $model->load($params, '');
        if ($result = $model->setDefault()) {
            return ['message' => '设置成功', 'data' => $result];
        }
    }

    /**
     * 获取入币地址
     * @author CGA
     */
    public function actionRechargeAddress()
    {
        $params = Yii::$app->request->post();
        $model = new Address();
        $model->setScenario(Address::SCENARIO_RECHARGEADDRESS);
        $model->load($params, '');
        if ($result = $model->getRechargeAddress()) {
            return ['message' => '获取成功', 'data' => $result];
        }
    }

    /**
     * 钱包余额列表
     * @author zcy
     */
    public function actionAssest()
    {
        $params = Yii::$app->request->post();
        $model = new Wallet();
        if ($result = $model->assestlist()) {
            return ['message' => '钱包余额列表获取成功', 'data' => $result];
        } else {
            return ['message' => '钱包余额列表获取成功', 'data' => []];
        }
    }

    /**
     * 获取钱包历史
     * @author CGA
     */
    public function actionCoinHistory()
    {
        $params = Yii::$app->request->post();
        $model = new Coin();
        $model->setScenario(Coin::SCENARIO_GET_HISTORY);
        $model->load($params, '');
        if ($result = $model->getCoinHistory()) {
            return ['message' => '获取钱包历史成功', 'data' => $result];
        }
    }

    /**
     * 获取收支类型
     * @author CGA
     */
    public function actionGetCategory()
    {
        $result = Coin::getCategorys();
        return ['message' => '获取成功', 'data' => $result];
    }
}
